package com.example.rabbitmq.consumer;

import com.example.rabbitmq.demos.web.mapper.LogMapper;
import com.example.rabbitmq.model.Log;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class Consumer {

    @Autowired
    private LogMapper logMapper;

    @RabbitListener(queues = "test_queue")
    public void receiveTopicLog(String logMessage) {
        saveLog(logMessage);
    }

    private void saveLog(String logMessage) {
        // 在这里将日志消息存储到数据库中
        Log log = new Log();
        log.setMessage(logMessage);
        logMapper.insert(log);
    }
}
